
# 编码格式声明(必须)
# -*- coding: gbk -*-

from datetime import datetime
from tick_manager import TickManager

from xtquant import xtdata
from fastapi import FastAPI
import scheduler
from router.kline import router as kline_router
from router.stock import router as stock_router
from router.info import router as info_router

from utils.stock import get_stock_list









# xtdata.download_sector_data()
# client = xtdata.get_client()
# client.down_all_sector_data()
# sector_list = xtdata.get_sector_list()
# print(xtdata.get_stock_list_in_sector("北证50等权"))


app = FastAPI()
app.include_router(kline_router, prefix="/kline")
app.include_router(stock_router, prefix="/stock")
app.include_router(info_router, prefix="/info")




# tick_manager = TickManager()
# def simulation(data={}):
#     start_time=data["start_time"] if "start_time" in data else datetime.now().replace(hour=9, minute=0, second=0, microsecond=0).strftime("%Y%m%d%H%M%S")
#     end_time=data["end_time"] if "end_time" in data else datetime.now().replace(hour=15, minute=30, second=0, microsecond=0).strftime("%Y%m%d%H%M%S")
  

    
#     stock_list=data["stock_list"] if "stock_list" in data else get_stock_list()
   
    
#     for code in stock_list:
#         tick=xtdata.get_market_data_ex(field_list=[],stock_list=[code],period="tick",start_time=start_time,end_time=end_time,count=-1,dividend_type='none', fill_data=False)
#         print("开始模拟",tick)
#         new_ticks=tick[code].to_dict(orient='records')
      
#         for tick_dict in new_ticks:
#             new_tick={}
#             new_tick[code]=tick_dict
#             tick_manager.trigger(new_tick)
            

       
# def actual_trading():
   
#     def callback(tick):
#         tick_manager.trigger(tick)
    
#     xtdata.subscribe_whole_quote(code_list=["SH","SZ","BJ"],callback=callback)
#     xtdata.run()


# simulation({"stock_list":["002467.SZ"],"start_time":"20250910090000","end_time":"20250910153000"})
# actual_trading()

# xtdata.run()

